package com.geotmt.billingcenter.modules;

import com.geotmt.billingcenter.common.entry.ConsumeStatisEntry;
import com.geotmt.billingcenter.common.utils.IpUtils;
import com.geotmt.billingcenter.common.vo.consume.ConsumeHisVo;
import com.geotmt.billingcenter.modules.consume.service.ConsumeService;
import com.geotmt.billingcenter.modules.hive.service.ConsumeHiveService;
import com.geotmt.billingcenter.modules.schedule.BcSchedule;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;


/**
 * @Description 类描述
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/4/10 10:54
 * @Version     v1
 **/
@RestController
@RequestMapping(value = "/test/")
public class TestController {

    @Resource
    private ConsumeHiveService consumeHiveService;

    @Resource
    private ConsumeService consumeService;

    @Resource
    private AmqpTemplate template;

    @Resource
    private BcSchedule bcSchedule;

    @Value("${master.ip}")
    private String masterIp;

    @RequestMapping(value = "/t1",method = RequestMethod.POST)
    public String tets(@RequestParam(value = "tableName") String tabelName){
        consumeHiveService.createTest(tabelName);
        return "success";
    }

    @RequestMapping(value = "/testConsumeSchedule",method = RequestMethod.POST)
    public String testConsume(){
        bcSchedule.hiveToMysqlForConsume();
        return "success";
    }

    @RequestMapping(value = "/testCostSchedule",method = RequestMethod.POST)
    public String testCost(){
        bcSchedule.hiveToMysqlForCost();
        return "success";
    }

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public Map<String,Object> list(String dayFlag, String dayFlag2){
        List<ConsumeStatisEntry> list = consumeHiveService.listConsume(dayFlag);
        List<ConsumeStatisEntry> list2 = consumeHiveService.listConsume2(dayFlag,dayFlag2);
        Map<String,Object> repMap = new HashMap<>(2);
        repMap.put("list1",list);
        repMap.put("list2",list2);
        System.out.println(IpUtils.isSame(masterIp));
        return repMap;
    }

    @RequestMapping(value = "/t4Mq",method = RequestMethod.POST)
    public String mq(@RequestParam(value = "msg") String msg){
        template.convertAndSend("topic.message",msg);
        return "success";
    }


    @RequestMapping(value = "/getMoney",method = RequestMethod.POST)
    public Object mq(@RequestBody Map<String,Object> map){
        Integer cuserId = Integer.parseInt(map.get("cuserId")+"");
        Integer interfaceId = Integer.parseInt(map.get("interfaceId")+"");
        ConsumeHisVo consume = consumeService.getConsume(null, null, cuserId, interfaceId, new Date());
        System.out.println(consume);
        return consume;
    }

    public static void main(String[] args) {



    }

}
